package com.alibaba.service;

import com.alibaba.bean.ValData;
import com.alibaba.bean.ValResult;
import com.alibaba.bean.Value;
import com.alibaba.mapper.ValueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ValueService {

    @Autowired
    private ValueMapper valueMapper;

    public ValResult estValue(Value value) {
        ValResult vr = new ValResult();
        ValData vd = new ValData();
        vr.setValSuccess(false);
        try{
            valueMapper.putAllValue(value);
            vr.setMsg("颜值数据存储成功");
            vr.setValSuccess(true);
            float f = value.getFaceValue();
            if (valueMapper.totalNum() >= 10) {
                float fd = valueMapper.findTopValue();
                if (f >= fd) {
                    vd.setTop(true);
                    vd.setObjectId(value.getObjectId());
                    vr.setValDetail(vd);
                } else {
                    vd.setTop(false);
                    vd.setObjectId(null);
                    vr.setValDetail(vd);
                }
            } else {
                vd.setTop(true);
                vd.setObjectId(value.getObjectId());
                vr.setValDetail(vd);
            }
        }catch (Exception e){
            vr.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return vr;
    }

}
